// pages/tool/card/index/detail/detail.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        threetype: ['商品信息', '印刷订单', '电子券分发订单'],
        status: {1: '未确认', 2: '印刷中', 3: '已完成'},
        distribute: {1: '分发中', 2: '已领取', 3: '已撤销'},
        nowIndex: 0,
        id: 0,
        cardinfo: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        app.func.onPageLoad(this, options);
        this.setData({
            id: options.id
        }, () => {
            this.carddetail(options.id)
        });
    },

    carddetail: function (id) {
        app.func.getPromise('/list/plandetail/' + id)
            .then(([code, res]) => {
                this.setData({cardinfo: res.data});
            })
    },


    operate:function(e){
        let status =  e.currentTarget.dataset.status;    // 1 去登录    2 去认证
        if(status == 1){
            wx.navigateTo({
                url: '/pages/auth/auth'
            })
        }else{
            wx.navigateTo({
                url: '/pages/auth/preattestation/preattestation'
            })
        }
    },


    forsbubmit: function (data) {
        app.func.postPromise('/cardtype/createcard', data)
            .then(([code, res]) => {
                if (code == 200) {
                    wx.navigateTo({
                        url: '/tools/pages/tool/card/make1/print/print?printid=' + res.data + '&skip=1'
                    })
                } else {
                    app.func.toastPromise(res.message)
                }
            })
    },
    print: function () {
        let data = this.data.cardinfo.param;
        data['cy_time_expire_v'] = data['cy_time_expire'];
        this.forsbubmit(data);
    },


    onTab: function (e) {
        let index = e.currentTarget.dataset.index;
        this.setData({nowIndex: index});
    },


    viewsku: function (e) {
        var id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/index/productdetail/productdetail?id=' + id
        })
    },

    preview: function (e) {
        var id = this.data.id;
        wx.navigateTo({
            url: '/tools/pages/tool/card/index/preview/preview?id=' + id
        })
    },

    printdetail: function (e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/about/card/print/detail/detail?id=' + id
        })
    },

    distributeDetail: function (e) {
        let id = this.data.id;
        let num = e.currentTarget.dataset.num;
        let id1 = e.currentTarget.dataset.id1;
        wx.navigateTo({
            url: `/pages/about/card/distribute/detail/detail?id=${id}&num=${num}&id1=${id1}`
        })
    },


    edit: function () {
        let id = this.data.id;
        wx.navigateTo({
            url: `/tools/pages/tool/card/make1/setInfo/setInfo?editcardinfo=${id}&cardplan=1`
        })
    }


})
